#!/bin/bash

# Script to compile patwarp
# Assumes metis is already compiled, will instruct user if it's not

# Check to make sure WARP3D_HOME is set
[ -z "$WARP3D_HOME" ] && echo "Need to set WARP3D_HOME before proceeding." && exit 1

# Move to this directory
cd $WARP3D_HOME/patwarp

# Check to make sure libmetis.a exists in the right spot
if [ ! -e $WARP3D_HOME/linux_packages/lib/libmetis.a ]; then
      echo "libmetis.a not found in $WARP3D_HOME/linux_packages/lib/"
      echo "Please run compile script in $WARP3D_HOME/linux_packages/source/metis-4.0"
      exit
fi

# Test compiler (no real point in proceeding without ifort)
hash ifort 2>&- || { echo >&2 "The Intel fortran compiler is required (ifort).  Aborting."; exit 1;}

# Now proceed.
echo "Compiling patwarp on Linux 64bit..."
ifort -O2 -static-intel -fixed -fpe0 patwarp_module.f patwarp.f \
      $WARP3D_HOME/linux_packages/lib/libmetis.a -o $WARP3D_HOME/run_linux_em64t/patwarp.go

echo "Executable is in run_linux_em64t"
